package monsmon.run;

import monsmon.game.*;
import monsmon.game.draw.*;
import monsmon.term.*;
import monsmon.control.*;
import java.awt.event.*;
import monsmon.game.parse.*;
import monsmon.util.*;
import monsmon.game.tmlt.*;
import java.awt.Color;
import monsmon.run.state.*;

public class MainLoop{
	
	private static final String files[] = {
		"../dat/ldefe.lvl"
	};

	private static Terminal __term = null;
	private static MonsGame __game;

	private static GameState cstate = null;
	private static GameState nstate = null;

	private static void __setup_mgame(){
		MonsGame m = Parser.parse(files);
		__game = m;
	}

	public static void init_game(){
		__term = new WinTerm();
		__term.init();
		__setup_mgame();
		set_state(new MainGameState(__game));
		main_loop();
	}

	public static void main_loop(){
		while(true){
			if(nstate != null){
				cstate = nstate;
				nstate = null;
			}
			cstate.procin(__term);
			cstate.update();
			cstate.render(__term);
			try{
				Thread.sleep(1000/90);
			}catch(Exception ex){}

		}
	}

	public static void set_state(GameState st){
		nstate = st;
	}
}
